package chapter8;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * ListIterator，和通用集合中的Iterator相比，ListIterator增加了add方法
 * 并且可以反向迭代
 */
public class ListIteratorTest {
    public static void main(String[] args) {
        String[] books = new String[] {
                "疯狂Java讲义",
                "疯狂iOS讲义",
                "轻量级Java EE企业应用实战"
        };
        List bookList = new ArrayList();
        for (int i = 0; i < books.length; i++) {
            bookList.add(books[i]);
        }
        ListIterator lt = bookList.listIterator();
        while (lt.hasNext()) {
            System.out.println(lt.next());
            lt.add("------分隔符------");
        }
        System.out.println("============下面开始反向迭代===========");
        while (lt.hasPrevious()) {
            System.out.println(lt.previous());
        }
    }
}
